package com.yuanchu.order.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yuanchu.order.entity.YoshopOrderEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 订单记录表
 *
 * @author adan
 * @email 2028038953@gmail.com
 * @date 2023-12-19 20:57:22
 */
@Mapper
public interface YoshopOrderDao extends BaseMapper<YoshopOrderEntity> {

    @Select("SELECT\n" +
            "    -- 将创建时间（create_time）字段格式化为日期字符串\n" +
            "    DATE(FROM_UNIXTIME(pay_time)) AS date,\n" +
            "    -- 统计每一天的订单总数\n" +
            "    COUNT(*) AS orderTotal,\n" +
            "    -- 计算每一天的订单总金额\n" +
            "    SUM(order_price) AS orderTotalPrice\n" +
            "FROM\n" +
            "    yoshop_order\n" +
            "WHERE\n" +
            "  -- 筛选条件：仅包括在过去7天内的订单，包括今天（当前日期）的订单\n" +
            "        pay_time >= UNIX_TIMESTAMP(CURDATE() - INTERVAL 7 DAY) AND\n" +
            "        pay_time <= UNIX_TIMESTAMP(NOW()) -- 或者直接使用 NOW()\n" +
            "GROUP BY\n" +
            "    date")
    List<Map<String, Object>> getTradeTrendItems();

    long queryOrderSalesByDay(long startTime, long endTime);


}
